package sealte.hvpms.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sealte.hvpms.dao.AdminDAO;
import sealte.hvpms.dao.impl.AdminDAOImpl;
import sealte.hvpms.pojo.Admin;

import com.google.gson.Gson;

public class AdminResetPassword extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html");
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Cache-Control","no-cache");
		PrintWriter out = response.getWriter();
		Admin admin = (Admin)request.getSession().getAttribute("admin");
		if(admin!=null){
			String aid = (String)request.getParameter("id");
			if(aid!=null&&!aid.equals("")){
				String message = "";
				AdminDAO ab = new AdminDAOImpl();
				int id = Integer.parseInt(aid);
				boolean flag = ab.modifyPassword(id,"666666");
				String name = ab.getNameByID(id);
				if(flag){
					message = "账号为["+name+"]的管理员重置密码成功，新密码为666666.";
				}else{
					message = "账号为["+name+"]的管理员重置密码失败！！";
				}
				Gson gson = new Gson();
				String json = gson.toJson(message);
				out.write(json);
			}else{
				out.println("系统错误");
			}
		}else{
			out.println("谢绝跨路径访问！");
		}
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		this.doPost(request, response);
	}
}
